package com.xinyu.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinyu.domain.EquipmentInfo;
import com.xinyu.domain.Label;
import com.xinyu.service.IEquipmentInfoService;
import com.xinyu.service.ILabelService;
import com.xinyu.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author: XinYu
 * @since 2025-02-17
 */
@RestController
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private ILabelService labelService;

    @GetMapping("/queryAll")
    public ResponseEntity<BaseResult> queryAll() {
        List<Label> list = labelService.lambdaQuery()
                .eq(Label::getIsDelete, 0)  // 查询未删除标签
                .list();

        return ResponseEntity.ok(BaseResult.ok(list));
    }
    /**
     * 分页查询 Label
     */
    @PostMapping("/list")
    public ResponseEntity<BaseResult> list(@RequestBody Map<String, Integer> params) {
        int pageNum = params.get("pageNum");
        int pageSize = params.get("pageSize");
        Page<Label> page = new Page<>(pageNum, pageSize);
        IPage<Label> result = labelService.selectLabelPage(page);
        return ResponseEntity.ok(BaseResult.ok(result));
    }

    /**
     * 新增 Label
     */
    @PostMapping("/save")
    public ResponseEntity<BaseResult> save(@RequestBody Label label) {
        labelService.save(label);
        return ResponseEntity.ok(BaseResult.ok());
    }

    /**
     * 修改 Label
     */
    @PostMapping("/update")
    public ResponseEntity<BaseResult> update(@RequestBody Label label) {
        labelService.updateById(label);
        return ResponseEntity.ok(BaseResult.ok());
    }

    /**
     * 删除 Label
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<BaseResult> delete(@PathVariable Integer id) {
        Label label = labelService.getById(id);
        label.setIsDelete(1);
        labelService.updateById(label);
        return ResponseEntity.ok(BaseResult.ok());
    }
}

